import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { HydratedDocument } from 'mongoose';

export type CommitDocumentType = HydratedDocument<CommitInfo>;
export type LogDocumentType = HydratedDocument<LogInfo>;

export type AidDocumentType = HydratedDocument<AidInfo>;

interface ICommit {
  userId: string;
  type: string;
  assId: string;
  username: string;
  content: string;
  time: number;
  avatar: string;
  replies: Array<ICommit>; // 数组类型使用 Array<ICommit>
  like: number;
  commit: number;
  level: number;
  parentId: string;
}

@Schema()
export class AidInfo {
  @Prop({ required: true })
  userId: string;

  @Prop({ required: true })
  time: number;

  @Prop({ required: true })
  content: string;


  @Prop({ required: true })
  username: string;

  @Prop({ required: true })
  avatar: string;

  @Prop({ required: true })
  status: number;


}

@Schema()
export class CommitInfo {
  // 用户id
  @Prop({ required: true })
  userId: string;

  @Prop({ required: true })
  type: string; // 组件类型

  @Prop({ required: true })
  assId: string; // 组件id

  @Prop({ required: true })
  username: string; // 用户名

  @Prop({ required: true })
  content: string; // 内容

  @Prop({ required: true })
  // 转化为时间戳
  time: number; // 时间

  @Prop({ required: true })
  avatar: string; // 头像

  @Prop({ required: true, type: [Object] })
  replies: ICommit[];

  @Prop({ required: true })
  like: number;

  @Prop({ required: true })
  commit: number;

  @Prop({ required: true })
  level: number;

  @Prop({ required: true })
  parentId: string;
}

@Schema()
export class LogInfo {
  @Prop({ required: true })
  content: string;

  //时间戳
  @Prop({ required: true })
  time: number;

  //颜色
  @Prop({ required: true })
  color: string;
}

export const CommitInfoSchema = SchemaFactory.createForClass(CommitInfo);
export const LogInfoSchema = SchemaFactory.createForClass(LogInfo);
export const AidInfoSchema = SchemaFactory.createForClass(AidInfo);